package com.example.Fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.Base.BaseFragment;
import com.example.adapter.MyItemClickListener;
import com.example.administrator.olddoctor.R;

import java.util.ArrayList;
import java.util.Map;


public class ProductionOnMyPostFragment extends BaseFragment {

    private View view ;
    private RecyclerView mrecyclerview;
    private Context context;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context = context;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_production_on_my_post, container, false);
        init();
        return view;
    }

    private void init(){
        mrecyclerview = (RecyclerView) view.findViewById(R.id.production_recylerview_post);
        mrecyclerview.setLayoutManager(new LinearLayoutManager(context));
        mrecyclerview.setItemAnimator(new DefaultItemAnimator());
//        mrecyclerview.addItemDecoration(new MyDecoration(context, MyDecoration.VERTICAL_LIST));
    }

    public void getDate(){


    }

    public void setAdapter(){


    }

    class MyAdapter extends RecyclerView.Adapter {
        private MyItemClickListener listener;
        private ArrayList<Map<String,Object>> list;
        public MyAdapter(MyItemClickListener listener) {this.listener = listener;}


        public void load(ArrayList<Map<String,Object>> list){
            if(null == this.list){
                this.list = list;
            } else {
                this.list.addAll(list);
            }
        }

        public void setItemOnClickListener (){


        }

        public void clearDate(){
            this.list.clear();
            this.notifyDataSetChanged();
        }

        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

            return null;
        }

        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        }

        @Override
        public int getItemCount() {
            return list.size();
        }

        @Override
        public int getItemViewType(int position) {
            if(!list.get(position).containsKey("type")){
                Log.e(getClass().getName(),"必须要有type属性在您的RecycleView的数据源中");}
            int type = (int) list.get(position).get("type");
            return type;
        }
    }

    class MyAttentionHolder extends RecyclerView.ViewHolder implements View.OnClickListener{


        public MyItemClickListener listener ;

        public MyAttentionHolder(View itemView , MyItemClickListener listener) {
            super(itemView);

        }

        @Override
        public void onClick(View v) {
            listener.itemClickListener(v,getPosition());
        }
    }

}
